package com.frank.loadinglibrary.common.search;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.render.Path;
import ohos.agp.utils.Color;
import ohos.agp.utils.Point;
import ohos.app.Context;

public class MagnifyComponent extends Component {

    Paint mPaint = new Paint();
    String pillarColor = "#0000ff";
    String glassColor = "#00ff00";

    public MagnifyComponent(Context context) {
        this(context, null);
    }

    public void setPillarColor(String pillarColor) {
        this.pillarColor = pillarColor;
    }

    public void setGlassColor(String glassColor) {
        this.glassColor = glassColor;
    }

    public MagnifyComponent(Context context, AttrSet attrSet) {
        this(context, attrSet, null);
    }

    public MagnifyComponent(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        initUI();

        DrawTask drawTask = new DrawTask() {
            @Override
            public void onDraw(Component component, Canvas canvas) {
                mPaint.setColor(new Color(Color.getIntColor(pillarColor)));
                float centerX = 1.9f * getWidth() / 3f;
                float centerY = 1.9f * getHeight() / 3f;
                float left = centerX - getWidth() / 2f;
                float top = centerX - 0.05f * getWidth();
                float right = centerX;
                float bottom = centerY + 0.05f * getWidth();
                canvas.rotate(45, centerX, centerY);
                canvas.drawRect(left, top, right, bottom, mPaint);
                canvas.restore();
                canvas.rotate(-45, centerX, centerY);
                canvas.drawCircle(getWidth() / 4, getHeight() / 4, getWidth() / 4, mPaint);
                mPaint.setColor(new Color(Color.getIntColor(glassColor)));
                canvas.drawCircle(getWidth() / 4, getHeight() / 4, getWidth() / 6, mPaint);
            }
        };
        addDrawTask(drawTask);
    }

    public float getRightEdge() {
        return (float) (1.9f * getWidth() / 3f + 0.036 * getWidth());
    }

    private float getBottomEdge() {
        return (float) (1.9f * getHeight() / 3f + 0.036 * getWidth());
    }

    private void initUI() {
        mPaint.setStyle(Paint.Style.FILL_STYLE);
        mPaint.setColor(new Color());
        mPaint.setAntiAlias(true);
    }


}
